import axios from 'axios'
import { Message } from 'element-ui'
const axiosGetToken = (userName, userPass, router, route) => {
  axios
    .get('http://61.181.255.77:17311/Hglibrary/login/loginselect?', {
      params: {
        uname: userName,
        upsd: userPass
      }
    })
    .then(function(response) {
      let data = response.data
      let code = parseInt(response.data.code)
      if (code === 0) {
        sessionStorage.setItem('user_token', 'admin')
        sessionStorage.setItem('user_name', name)
        let USER_TOKEN = sessionStorage.getItem('user_token')
        if (USER_TOKEN != null) {
          router.push(route.query.redirect || '/')
        }
      } else {
        Message({
          showClose: true,
          message: data.message,
          type: 'error'
        })
        return false
      }
    })
    .catch(function(error) {
      console.log(error)
    })
}

export default axiosGetToken
